home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SunSoft Catalyst CDWARE 1996 May to August
/
Catalyst CDWARE 1996 May to August.iso
/
.products
/
JavaWorld
/
javaworld
/
cgi-bin
/
jw-np-mailto.cgi
< prev
next >
Wrap
Text File
|
1996-02-15
|
7KB
|
216 lines
#!/usr/local/bin/perl
# jw-np-mailto.cgi - script to process e-mail sent from JavaWorld's
# new-products page. this is a kludge until the html mailto becomes ubiquitous.
#
# usage: jw-np-mailto.cgi <recipient> [ <return href> <return tag> | send ]
#
# if 'send' is the last command-line argument, jw-np-mailto.cgi assumes
# that it is to send the enclosed datastream to the recipient denoted by
# the first command-line argument. otherwise, it interprets the second
# and third command-line arguments as a return href and tag for 'back-to'
# functionality.
#
# it's fairly crucial that the e-mail address does not contain +
# signs, as this will confuse jw-np-mailto.cgi's interpretation of
# command-line arguments.
#
# complain to david.burnette@javaworld.com if there are problems.
if ("$ARGV[$#ARGV]" eq "send") { # send e-mail message
$defaultfrom="javaworld\@javaworld.com";
$defaultname="JavaWorld";
$mailprog="/usr/lib/sendmail";
$bcc="jwbcc\@javaworld.com"; # recipient of failsafe copy
$bccname="JW bcc";
$bccsubject="bccmail to $ARGV[0]\@$ARGV[1]";
$date=`date`; chop($date);
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
if (@ARGV < 3) {
$recipient="david.burnette\@javaworld.com";
$href1="/index.html";
$src1="/icons/b-thismonth.gif";
$alt1="[This month's table of contents]";
}
elsif (@ARGV == 3) {
$recipient="$ARGV[0]\@$ARGV[1]";
$href1="/index.html";
$src1="/icons/b-thismonth.gif";
$alt1="[This month's table of contents]";
}
elsif (@ARGV == 4) {
$recipient="$ARGV[0]\@$ARGV[1]";
$href1="$ARGV[2]";
$src1="/icons/b-thismonth.gif";
$alt1="[This month's table of contents]";
}
else {
$recipient="$ARGV[0]\@$ARGV[1]";
$href1="/index.html";
$src1="/icons/b-thismonth.gif";
$alt1="[This month's table of contents]";
$href2="$ARGV[2]#$ARGV[3]";
$src2="/icons/b-backtostory.gif";
$alt2="[Back to story]";
}
$HREF1="<A HREF=\"$href1\"><IMG SRC=\"$src1\" ALT=\"$alt1\"></A>";
$HREF2="<A HREF=\"$href2\"><IMG SRC=\"$src2\" ALT=\"$alt2\"></A>" if defined($href2);
# Split the name-value pairs
@pairs = split(/&/,$buffer);
foreach $pair (@pairs)
{
($name,$value) = split(/=/,$pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
# Stop people from using subshells to execute commands
$value =~ s/~!/ ~!/g;
$FORM{$name} = $value;
}
# check for empty message; thwart bastards
if ($FORM{'name'} =~ /^[\s]*$/ || $FORM{'email'} =~ /^[\s]*$/ || $FORM{'message'} =~ /^[\s]*$/) {
print "Content-TYPE: text/html\n\n";
print "<HTML>\n";
print "<HEAD><TITLE>JavaWorld-E-mail Form</TITLE></HEAD>\n";
print "<BODY>\n";
print "<H3>An empty message cannot be sent. It must contain a name, e-mail address, and message.</H3>\n";
print "<H3>To send a message, return to the mail form by hitting your browser\'s back button.</H3>\n";
print "</BODY>\n";
print "</HTML>\n";
}
else { # send thank-you note to browser
print "Content-TYPE: text/html\n\n";
print "<HTML>\n";
print "<HEAD><TITLE>JavaWorld</TITLE></HEAD>\n";
print "<BODY>\n";
print "$HREF1$HREF2\n";
print "<H3>Thank you for sending mail to $recipient. We appreciate your patronage.</H3>\n";
print "</BODY>\n";
print "</HTML>\n";
# send failsafe copy of raw data to bcc
open(MAIL,"|$mailprog $bcc") || die "cannot open $mailprog\n";
print MAIL "From: $bcc ($bccname)\n";
print MAIL "To: $bcc\n";
print MAIL "Subject: $bccsubject\n\n";
print MAIL "BEGIN RECORD $date\n";
print MAIL "recipient=$recipient\n";
print MAIL "href1=$href1\n";
print MAIL "src1=$src1\n";
print MAIL "alt1=$alt1\n";
print MAIL "href2=$href2\n";
print MAIL "src2=$src2\n";
print MAIL "alt2=$alt2\n";
print MAIL "CONTENT_LENGTH=$ENV{'CONTENT_LENGTH'}\n";
print MAIL "CONTENT_TYPE=$ENV{'CONTENT_TYPE'}\n";
print MAIL "DOCUMENT_ROOT=$ENV{'DOCUMENT_ROOT'}\n";
print MAIL "GATEWAY_INTERFACE=$ENV{'GATEWAY_INTERFACE'}\n";
print MAIL "HTTP_REFERER=$ENV{'HTTP_REFERER'}\n";
print MAIL "HTTP_USER_AGENT=$ENV{'HTTP_USER_AGENT'}\n";
print MAIL "QUERY_STRING=$ENV{'QUERY_STRING'}\n";
print MAIL "REMOTE_ADDR=$ENV{'REMOTE_ADDR'}\n";
print MAIL "REMOTE_HOST=$ENV{'REMOTE_HOST'}\n";
print MAIL "REQUEST_METHOD=$ENV{'REQUEST_METHOD'}\n";
print MAIL "SCRIPT_NAME=$ENV{'SCRIPT_NAME'}\n";
print MAIL "SERVER_NAME=$ENV{'SERVER_NAME'}\n";
print MAIL "SERVER_PORT=$ENV{'SERVER_PORT'}\n";
print MAIL "SERVER_PROTOCOL=$ENV{'SERVER_PROTOCOL'}\n";
print MAIL "SERVER_SOFTWARE=$ENV{'SERVER_SOFTWARE'}\n";
print MAIL "ARGV=@ARGV\n";
print MAIL "STDINDATA=$buffer\n";
print MAIL "END RECORD $date\n";
close(MAIL);
# send mail to $recipient
open(MAIL,"|$mailprog $recipient") || die "cannot open $mailprog\n";
print MAIL "From: $FORM{'email'} ($FORM{'name'})\n";
print MAIL "To: $recipient\n";
print MAIL "Subject: $FORM{'subject'}\n\n";
print MAIL "$FORM{'message'}\n";
print MAIL "\n------------------------------------------------------------\n\n";
print MAIL "New products e-mail from JavaWorld (http://www.javaworld.com)\n\n";
print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n";
print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n";
print MAIL "Server name: $ENV{'SERVER_NAME'}\n";
print MAIL "Browser: $ENV{'HTTP_USER_AGENT'}\n";
print MAIL "HTTP_REFERER: $ENV{'HTTP_REFERER'}\n";
close(MAIL);
} # end of if bastard else sendmail
exit(0);
}
else { # present message form to browser
if (@ARGV < 2) {
$recipient="webmaster\@javaworld.com";
$href="/index.html";
}
elsif (@ARGV == 2) {
$recipient="$ARGV[0]\@$ARGV[1]";
$href="/index.html";
}
elsif (@ARGV == 3) {
$recipient="$ARGV[0]\@$ARGV[1]";
$href="$ARGV[2]";
}
else {
$recipient="$ARGV[0]\@$ARGV[1]";
$href="$ARGV[2]+$ARGV[3]";
}
$banner="Send mail to $recipient";
print <<END_OF_FORM;
Content-TYPE: text/html
<HTML>
<HEAD><TITLE>JavaWorld E-mail Form</TITLE></HEAD>
<BODY>
<FORM METHOD=POST ACTION="http://www.javaworld.com/cgi-bin/jw-np-mailto.cgi?$ARGV[0]+$ARGV[1]+$href+send">
<P>
<BLOCKQUOTE>
<H2><EM>JavaWorld</EM> is an independent publication of IDG Communications.</H2>
</BLOCKQUOTE>
<P>
<CENTER><H2>$banner</H2></CENTER>
<P>
<STRONG>Your Name:</STRONG>
<INPUT TYPE="text" NAME="name" SIZE ="40">
<P>
<STRONG>Your e-mail address:</STRONG>
<INPUT TYPE="text" NAME="email" SIZE ="40">
<P>
<STRONG>Subject:</STRONG>
<INPUT TYPE="text" NAME="subject" SIZE ="40">
<P>
<STRONG>Please enter your message below:</STRONG><BR>
<TEXTAREA COLS=60 ROWS=10 NAME="message"></TEXTAREA>
<BR>
<INPUT TYPE="submit" VALUE="Send message">
<INPUT TYPE="reset" VALUE="Clear form"</P>
</FORM>
</BODY>
</HTML>
END_OF_FORM
exit(0);
}